package train48days;

import java.util.Scanner;

public class 最长公共子序列 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String m = sc.next();
            String n = sc.next();
            int res = LCS(m, n);
            System.out.println(res);
        }
    }

    private static int LCS(String m, String n) {
        int lenm = m.length();
        int lenn = n.length();
        int[][] dp = new int[lenm + 1][lenn + 1];
        for (int i = 1; i <= lenm; i++) {
            for (int j = 1; j <= lenn; j++) {
                if (m.charAt(i - 1) == n.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        return dp[lenm][lenn];
    }
}
